package cn.life.business.audit.controller;

import cn.life.business.apply.entity.po.ApplyPo;
import cn.life.business.audit.entity.po.AuditPo;
import cn.life.business.audit.service.AuditService;
import cn.life.common.entity.model.CMessage;
import cn.life.common.entity.model.MyUser;
import cn.life.common.entity.model.MyUserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author 王振宇
 * @Description: 审查控制层
 * @Date 2018-09-18 22:08:14
 */
@RestController
@RequestMapping("audit")
public class AuditController {

    @Autowired
    private AuditService auditService;

    /**
     * @param auditPo,myUserInfo
     * @return
     * @Description: 自动添加项
     */
    public void getOpr(AuditPo auditPo,MyUserInfo myUserInfo) {
        auditPo.setOprUserId(myUserInfo.getUserId());
        auditPo.setOprUserName(myUserInfo.getUserName());
        auditPo.setOprDate(new Date());
    }

    /**
     * @Description: 添加审查记录
     * @param auditPo
     * @return
     */
    @PostMapping(value = "/addaudit")
    public CMessage addAudit(@RequestBody AuditPo auditPo, @MyUser MyUserInfo myUserInfo){
           getOpr(auditPo,myUserInfo);
           return auditService.addAudit(auditPo);
    }

    /**
     * @Description: 修改审查状态
     * @param auditPo
     * @return
     */
    @PostMapping(value = "/update_state")
    public CMessage updateState(@RequestBody AuditPo auditPo){
        return auditService.updateState(auditPo);
    }

    /**
     * @Description: 导出申请单
     * @param auditPo
     * @return
     */
    @PostMapping(value = "/exportPdf")
    public CMessage exportPdf(HttpServletRequest request, @RequestBody AuditPo auditPo){
        return auditService.exportPdf(request,auditPo);
    }
}
